# To change this template, choose Tools | Templates
# and open the template in the editor.

class MaterialsPublisher < ActiveRecord::Base
  belongs_to :material, :class_name => "Material"
  belongs_to :publisher, :class_name => "Publisher"

  def self.search(publisher_id, search_title, page)
    items_per_page = count_record_per_page :materials_publishers
    order = "order_list"
    conditions_clauses = []
    conditions_options = []

    conditions_clauses << "publisher_id = ?"
    conditions_options << publisher_id
=begin
    #TODO: falta buscar por el titulo de materiales
    if search_title.size != 0
      conditions_clauses << "upper(title) like upper(?)"
      conditions_options << "%#{search_title}%"
    end
=end
    conditions = [conditions_clauses.join(" AND "), conditions_options].flatten
    total = count(:conditions => conditions)
    materials_publisher = MaterialsPublisher.paginate :per_page => items_per_page,:page => page, :conditions => conditions, :order => order
    return materials_publisher, total
  end
end
